nixos/binfmt: Add QEMU wrapper to preserve argv[0]#143060
nixos/binfmt: Add QEMU wrapper to preserve argv[0]#1430600x4A6F merged 3 commits intoNixOS:masterfrom
Conversation
|
Dup of #118926 |
|
Whoops, wasn't aware of that PR and GitHub wasn't returning good results for my searches. However, I still think the implementation here is more robust and only affects QEMU (not wine, for example). |
bc969b5 to
aed1cf6
Compare
|
I implemented the suggestion from @oxalica in #115406 (comment) and coreutils can now be built under binfmt. I did a |
|
Also we should update the PR title. |
aed1cf6 to
8631fff
Compare
5c65b40 to
724d53c
Compare
724d53c to
463294c
Compare
|
Looks like To reproduce:
|
c45d694 to
5d0aa2a
Compare
oxalica
left a comment
There was a problem hiding this comment.
Just need more docs. It works pretty fine now.
I've started a build of riscv64 coreutils with binfmt from this PR. Hope it could pass tests.
|
riscv64-linux |
5d0aa2a to
9e5d0a9
Compare
|
True to your word this does appear to fix the |
|
@ofborg test systemd-binfmt (I want to see what happens when this runs on an aarch64 machine) |
0x4A6F
left a comment
There was a problem hiding this comment.
Tests successfully run against rebased master.
LGTM
Motivation for this change
This PR enables argv[0] preservation for the QEMU binfmt-misc rules generated by
boot.binfmt.emulatedSystems. It allows certain packages that rely on argv[0] in their build process (e.g., coreutils for its tests) to correctly build under binfmt.Traditionally, the emulator invoked by
binfmt-miscdoesn't know what the original argv[0] is when running an executable, because only the absolute path to the foreign executable is passed. Currently, the emulator will simply use the full path as argv[0]. This leads to problems with multi-call executables as well as diff-based test methodologies used in various packages. For example, coreutils relies on output comparison in many test cases:binfmt-miscnow has the "P" flag that, when enabled, will add an extra argument after the absolute path to the foreign binary containing the original argv[0]. However, this also means that CLI compatibility with existing emulator executables is broken. SUSE has been carrying a patch since 2011 to add-binfmtwrappers that translate the new arguments into ones that regular QEMU accepts (-0for overriding argv[0]). There have been attempts to resolve this issue upstream, but so far there seems to be no consensus.This PR adds a statically-linked wrapper for QEMU that translates the arguments. It's possible to rewrite the arguments in the wrapper script that we use (#118926), but that still leaves some remaining issues (e.g., extraneous output when setting LD_PRELOAD).
Tested by building coreutils for riscv64-linux on x86_64-linux under binfmt (before, after).
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"./result/bin/)